package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteWeixinService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class RemoteWeixinFallbackFactory implements FallbackFactory<RemoteWeixinService> {
    private static final Logger log = (Logger) LoggerFactory.getLogger(RemoteWeixinFallbackFactory.class);

    @Override
    public RemoteWeixinService create(Throwable throwable) {
        log.error("微信发送客服消息调用失败:{}", throwable.getMessage());
        return new RemoteWeixinService() {
            @Override
            public AjaxResult wxMpKefuMessage(String toUser, String content, String source) {
                return AjaxResult.error("微信发送客服消息调用失败:" + throwable.getMessage());
            }
        };
    }
}
